﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;

namespace Enterprise.Management.Common
{
    public class Security
    {
        private const string HASH_PROVIDER = "MD5CryptoServiceProvider";
        private const string HASH_PROVIDER_WITHOUT_SALE = "MD5CryptoServiceProviderWithoutSalt";
        private const string SYMMETRIC_PROVIDER = "DPAPI Symmetric Crypto Provider";

        public static string MD5(string content)
        {
            return MD5(content, true);
        }

        public static string MD5(string content, bool salt)
        {
            string provider = salt ? Security.HASH_PROVIDER : Security.HASH_PROVIDER_WITHOUT_SALE;
            return Cryptographer.CreateHash(provider, content);
        }

        public static bool CompareMD5(string content, string hash)
        {
            return CompareMD5(content, hash, true);
        }

        public static bool CompareMD5(string content, string hash, bool salt)
        { 
            string provider = salt ? Security.HASH_PROVIDER : Security.HASH_PROVIDER_WITHOUT_SALE;
            return Cryptographer.CompareHash(provider, content, hash);
        }

        public static string Encrypt(string content)
        {
            return Cryptographer.EncryptSymmetric(Security.SYMMETRIC_PROVIDER, content);
        }

        public static string Decrypt(string content)
        {
            return Cryptographer.DecryptSymmetric(Security.SYMMETRIC_PROVIDER, content);
        }
    }
}